package com.itxiuyixiu.homework.entity.dao;

import com.itxiuyixiu.homework.entity.model.Teacher;
import com.itxiuyixiu.homework.entity.vo.TeacherVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 黄磊
 * @date 2020/3/5
 */
public interface TeacherDao extends JpaRepository<Teacher, Integer> {
    boolean existsByAcademyId(int academyid);

    @Transactional(readOnly = true)
    @Query(value = "select id, contract,identifyCard,sex, gmtCreated, gmtModified, teacherMessage, teacherName, fk_academy_id as academyId from Teacher where id=?1", nativeQuery = true)
    List<TeacherVo> findAllById(int teacherId);

    @Transactional(readOnly = true)
    @Query(value = "select id, contract,identifyCard,sex, gmtCreated, gmtModified, teacherMessage, teacherName, fk_academy_id as academyId from Teacher where teacherName=?1", nativeQuery = true)
    List<TeacherVo> findAllByTeacherName(String teacherName);

    @Transactional(readOnly = true)
    @Query(value = "select id, contract,identifyCard,sex, gmtCreated, gmtModified, teacherMessage, teacherName, fk_academy_id as academyId from Teacher", nativeQuery = true)
    List<TeacherVo> findAllTeachers();
}
